import java.util.Random;

public class Chance {

	private static String[] chanceCard = { 	"images/Chance Cards/01 - Speeding Fine.png", "images/Chance Cards/02 - Collect Dividend.png",
										 	"images/Chance Cards/03 - Advance to Trafalgar.png", "images/Chance Cards/04 - Advance to Go.png",
										 	"images/Chance Cards/05 - Pay School Fees.png", "images/Chance Cards/06 - Advance to Mayfair.png",
										 	"images/Chance Cards/08 - Street Repairs.png", "images/Chance Cards/09 - General Repairs.png",
										 	"images/Chance Cards/10 - Advance to Pall Mall.png", "images/Chance Cards/11 - Trip to Marylebone Station.png",
										 	"images/Chance Cards/12 - Building loan matures.png", "images/Chance Cards/13 - Go to Jail.png",
										 	"images/Chance Cards/14 - Back 3 spaces.png", "images/Chance Cards/15 - Drunk in charge.png",
										 	"images/Chance Cards/16 - Won crossword competiton.png", "images/Chance Cards/07 - Get out of Jail.png",
										 	"images/Chance Cards/00 - Chance.png"};
	private static int pick;									 	
	private static boolean jailCard = false;
	
	public static void drawCard() {
		
		Random draw = new Random();
		
		if (Chance.getJailCard() == false) {
			
			Chance.setPick(draw.nextInt(16));
		}
		
		else {
			
			Chance.setPick(draw.nextInt(15));
		}
	}
	
	public static Player implementCard(Player a) {
		
		switch(Chance.getPick()) {
		
			case 0:
				a = speedingFine(a);
				break;
			case 1:
				a = getDividend(a);
				break;
			case 2:
				a = advanceToTrafalgar(a);
				break;
			case 3:
				a = advanceToGo(a);
				break;
			case 4:
				a = paySchoolFee(a);
				break;
			case 5:
				a = advanceToMayfair(a);
				break;
			case 6:
				a = streetRepairs(a);
				break;
			case 7:
				a = generalRepairs(a);
				break;
			case 8:
				a = advanceToPallMall(a);
				break;
			case 9:
				a = advanceToMarylebone(a);
				break;
			case 10:
				a = loanMatures(a);
				break;
			case 11:
				a = goToJail(a);
				break;
			case 12:
				a = goBackThreeSpaces(a);
				break;
			case 13:
				a = drunkCharge(a);
				break;
			case 14:
				a = wonCrosswordCompetition(a);
				break;
			case 15:
				a = outOfJailFree(a);
				break;
		}
		
		return a;
	}

	public static String getChanceURL(int x) {
		
		return chanceCard[x];
	}

	public static int getPick() {
		
		return pick;
	}

	public static void setPick(int pick) {
		
		Chance.pick = pick;
	}
	
	public static boolean getJailCard() {
		
		return jailCard;
	}

	public static void setJailCard(boolean jailCard) {
		
		Chance.jailCard = jailCard;
	}

	public static Player speedingFine(Player a) {
		
		if (a.getCash() >= 75) {
			
			a.setCash(a.getCash()-75);
		}
		
		else {
			//PROMPT
		}
		
		return a;
	}
	
	public static Player getDividend(Player a) {
		
		a.setCash(a.getCash()+50);
		
		return a;
	}
	
	public static Player advanceToTrafalgar(Player a) {
		
		Location.setRelocate(true);
				
		if (a.getCurrLoc() > LotTiles.TS.getLocation()) {
			
			a.setStop(LotTiles.TS.getLocation()+40);
		}
		
		else {
			
			a.setStop(LotTiles.TS.getLocation());
		}
				
		return a;
	}
	
	public static Player advanceToGo(Player a) {
		
		Location.setRelocate(true);
		a.setStop(40);
		
		return a;
	}
	
	public static Player paySchoolFee(Player a) {
		
		if (a.getCash() >= 200) {
			
			a.setCash(a.getCash()-200);
		}
		
		else {
			//PROMPT
		}
		
		return a;
	}

	public static Player advanceToMayfair(Player a) {
		
		Location.setRelocate(true);
		a.setStop(LotTiles.M.getLocation());
		
		return a;
	}
	
	public static Player outOfJailFree(Player a) {
			
		a.setOutOfJailCard1(true);
		Chance.setJailCard(true);
		
		return a;
	}

	public static Player streetRepairs(Player a) {
		
		Properties properties = a.getProperties();
		
		int fine = (properties.getHousesOwned()*40)+(properties.getHotelsOwned()*115);
		
		if (a.getCash() >= fine) {
			
			a.setCash(a.getCash()-fine);
		}
		
		else {
			//PROMPT
		}
		
		return a;
	}
	
	public static Player generalRepairs(Player a) {
		
		Properties properties = a.getProperties();
		
		int fine = (properties.getHousesOwned()*25)+(properties.getHotelsOwned()*100);
		
		if (a.getCash() >= fine) {
			
			a.setCash(a.getCash()-fine);
		}
		
		else {
			//PROMPT
		}
		
		return a;
	}
	
	public static Player advanceToPallMall(Player a) {
		
		Location.setRelocate(true);
		
		if (a.getCurrLoc() > LotTiles.PM.getLocation()) {
			
			a.setStop(LotTiles.PM.getLocation()+40);
		}
		
		else {
			
			a.setStop(LotTiles.PM.getLocation());
		}
		
		return a;
	}

	public static Player advanceToMarylebone(Player a) {
	
		Location.setRelocate(true);
		
		if (a.getCurrLoc() > TrainTiles.MS.getLocation()) {
			
			a.setStop(TrainTiles.MS.getLocation()+40);
		}
		
		else {
			
			a.setStop(TrainTiles.MS.getLocation());
		}
		
		return a;
	}
	
	public static Player loanMatures(Player a) {
		
		a.setCash(a.getCash()+200);
		
		return a;
	}
	
	public static Player goToJail(Player a) {
		
		a.setStop(50);
		a.presetNextLoc(10);			
		a.setJail(true);
		a.setJailCounter(4);
		Location.setRelocate(true);
		Board.setIgnoreGo(true);
		
		return a;
	}
	
	public static Player goBackThreeSpaces(Player a) {
		
		Location.setRelocate(true);
		
		a.setStop(a.getCurrLoc()+37);
		Board.setIgnoreGo(true);
		
		System.out.println(Board.getIgnoreGo());
		
		return a;
	}
	
	public static Player drunkCharge(Player a) {
		
		if (a.getCash() >= 20) {
			
			a.setCash(a.getCash()-20);
		}
		
		else {
			//PROMPT
		}
		
		return a;
	}
	
	public static Player wonCrosswordCompetition(Player a) {
		
		a.setCash(a.getCash()+20);
		
		return a;
	}
}
